<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Title</title>
    <script src="../js/vue.js"></script>
</head>

<body>
    <div id="app">
        <cpn :cnum1="num1" :cnum2="num2" @num1change="num1change" @num2change="num2change"></cpn>
    </div>



    <template id="CPN">
        <div>
            <h2>测试</h2>

            <h2>num1::{{dnum1}}</h2>
            <!-- <input type="text" v-model="dnum1"> -->
            <input type="text" :value="dnum1" @input="dnum1Input">
            <h2>num2::{{dnum2}}</h2>
            <!-- 使用v-model对num1做双向绑定 -->
            <!-- <input type="text" v-model="dnum2"> -->


           
            <input type="text" :value="dnum2" @input="dnum2Input">
        </div>
    </template>
    <script>
        const vm = new Vue({
            el: '#app',
            data: {
                message: '我是你爹!',
                num1: 1,
                num2: 2,
            },
            methods: {
                num1change(dnum1) {
                    console.log('1111111111绕绕绕：：：' + dnum1);
                },
                num2change(dnum2) {
                    console.log('2222222真tm有点子绕啊：：：' + dnum2);
                }
            },

            components: {
                cpn: {
                    template: '#CPN',
                    data() {
                        return {
                            dnum1: this.num1,
                            dnum2: this.num2,
                        }
                    },
                    props: {
                        cnum1: {
                            type: Number,
                            default: 0
                        },
                        cnum2: {
                            type: Number,
                            default: 0
                        }
                    },
                    methods: {
                        dnum1Input(event) {
                            this.dnum1 = event.target.value;
                            this.$emit('num1change', this.dnum1);
                        },
                        dnum2Input(event) {
                            this.num2 = event.target.value;
                            this.$emit('num2change', this.dnum2);
                        }
                    }
                }
            }
        });
    </script>
</body>

</html>